<?php
include DIR_WS_CLASSES . 'kreditor_lang.php'; // xxx
require_once DIR_WS_CLASSES . 'kreditor.php';
global $kred_sek, $kred_nok, $kred_dkk, $kred_eur, $KRED_ISO3166_FI, $KRED_ISO3166_SE, $KRED_ISO3166_DK, $KRED_ISO3166_NO, $KRED_ISO3166_DE;
// Get the country specific settings based on currency
switch(strtolower($currency))
{
case 'sek':
$klarna_pclass = MODULE_PAYMENT_PCKREDITOR_PCLASS_DEFAULT;
$klarna_curr = $KRED_SEK;
$klarna_lang_month = KREDITOR_LANG_INFO_SE_PAYMENTTEXT2_EACH;
$klarna_lang_from = KREDITOR_LANG_INFO_SE_PARTPAYMENT_FROM;
$klarna_enabled = MODULE_PAYMENT_PCKREDITOR_STATUS;
$klarna_eid = MODULE_PAYMENT_PCKREDITOR_EID;
$klarna_country = "se";
$klarna_cc = $KRED_ISO3166_SE;
break;

case 'nok':
$klarna_pclass = MODULE_PAYMENT_PCKREDITOR_NOR_PCLASS_DEFAULT;
$klarna_curr = $KRED_NOK;
$klarna_lang_month = KREDITOR_LANG_INFO_NO_PAYMENTTEXT2_EACH;
$klarna_lang_from = KREDITOR_LANG_INFO_NO_PARTPAYMENT_FROM;
$klarna_enabled = MODULE_PAYMENT_PCKREDITOR_NOR_STATUS;
$klarna_eid = MODULE_PAYMENT_PCKREDITOR_NOR_EID;
$klarna_country = "no";
$klarna_cc = $KRED_ISO3166_NO;
break;

case 'dkk':
$klarna_pclass = MODULE_PAYMENT_PCKREDITOR_DEN_PCLASS_DEFAULT;
$klarna_curr = $KRED_DKK;
$klarna_lang_month = KREDITOR_LANG_INFO_DK_PAYMENTTEXT2_EACH;
$klarna_lang_from = KREDITOR_LANG_INFO_DK_PARTPAYMENT_FROM;
$klarna_enabled = MODULE_PAYMENT_PCKREDITOR_DEN_STATUS;
$klarna_eid = MODULE_PAYMENT_PCKREDITOR_DEN_EID;
$klarna_country = "dk";
$klarna_cc = $KRED_ISO3166_DK;
break;

case 'eur':
$hasgerman = false;
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { 

	$langarr=explode(",",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);

	foreach ($langarr as $lang) {
		$langcode=substr($lang,0,2);
		
		if(strtolower($langcode) == "de") {
			$hasgerman = true;
			break;
		}
	}
} 

if($_SESSION["language"] == "german" || $hasgerman) {
$klarna_pclass = MODULE_PAYMENT_PCKREDITOR_DE_PCLASS_DEFAULT;
$klarna_curr = $KRED_EUR;
$klarna_lang_month = KREDITOR_LANG_INFO_DE_PAYMENTTEXT2_EACH;
$klarna_lang_from = KREDITOR_LANG_INFO_DE_PARTPAYMENT_FROM;
$klarna_country = "de";
$klarna_eid = MODULE_PAYMENT_PCKREDITOR_DE_EID;
$klarna_enabled = MODULE_PAYMENT_PCKREDITOR_DE_STATUS;
$klarna_fee = 195;
$klarna_rate = 1495;
$klarna_cc = $KRED_ISO3166_DE;
} else { 
$klarna_pclass = MODULE_PAYMENT_PCKREDITOR_FIN_PCLASS_DEFAULT;
$klarna_curr = $KRED_EUR;
$klarna_lang_month = KREDITOR_LANG_INFO_FI_PAYMENTTEXT2_EACH;
$klarna_lang_from = KREDITOR_LANG_INFO_FI_PARTPAYMENT_FROM;
$klarna_country = "fi";
$klarna_eid = MODULE_PAYMENT_PCKREDITOR_FIN_EID;
$klarna_enabled = MODULE_PAYMENT_PCKREDITOR_FIN_STATUS;
$klarna_fee = 395;
$klarna_rate = 2200;
$klarna_cc = $KRED_ISO3166_FI;
}
break;
}

if(is_numeric($klarna_pclass) && $klarna_enabled == 'True')
{
switch(strtolower($currency))
{
case 'sek':
monthly_cost($cart->show_total()*$currencies->get_value($currency)*100, 1950, 24, 2900, 0, $klarna_cc, $result);
break;

case 'dkk':
monthly_cost($cart->show_total()*$currencies->get_value($currency)*100, 2200, 24, 3900, 0, $klarna_cc, $result);
break;

case 'nok':
monthly_cost($cart->show_total()*$currencies->get_value($currency)*100, 2200, 24, 4500, 0, $klarna_cc, $result);
break;

case 'eur':
monthly_cost($cart->show_total()*$currencies->get_value($currency)*100, $klarna_rate, 24, $klarna_fee, 0, $klarna_cc, $result);
break;
}
    $info_box_contents[] = array('align' => 'right',
                                 'text' => "<span class=\"klarna_pp_text\">" . $klarna_lang_from . "</span>");
	
	$info_box_contents[] = array('align' => 'right',
                                 'text' => '<span style="color: red; font-weight: bold;" class="klarna_pp_span">' . $currencies->format(ceil($result)/$currencies->get_value($currency)/100) . $klarna_lang_month . '</span><br /><script type="text/javascript" src="http://integration.klarna.com/js/klarnapart.js"></script>
<script>addKlarnaPartPaymentEvent(function() { InitKlarnaPartPaymentElements("klarna_partpayment_cart", ' . $klarna_eid . ', "' . $klarna_country . '"); });</script>
	<a href="#" id="klarna_partpayment_cart" onclick="ShowKlarnaPartPaymentPopup();return false;"></a>');	
	
}								 
?>